package router

import (
	"community_end/api"
	"community_end/middleware"
	"community_end/model"
	"community_end/utils"
	"github.com/gin-gonic/gin"
)

func InitRouter() {
	model.InitDB()
	gin.SetMode(utils.AppMode)
	r := gin.Default()
	r.Use(middleware.Cors())

	auth := r.Group("", middleware.JwtToken())
	{
		auth.GET("/user/info", api.GetUserByUsername)
		auth.GET("/user/logout", api.UserLogout)
		auth.POST("/post/create", api.InsertPost)
		auth.GET("/relationship/validate/:id", api.ValidateRelationship)
		auth.GET("/relationship/subscribe/:id", api.RelationshipSubscribe)
		auth.GET("/relationship/unsubscribe/:id", api.RelationshipUnSubscribe)
		auth.POST("/comment/add_comment", api.InsertComment)
		auth.POST("/post/update", api.UpdatePost)
		auth.DELETE("/post/delete/:id", api.DeleteTopic)
		//auth.GET("/user//:username", api.UserInfo)
	}
	r.GET("/billboard/show", api.SelectAllBillBoard)
	r.GET("/tip/today", api.SelectTodayTip)
	r.GET("/promotion/all", api.SelectAllPromotion)
	r.POST("/user/register", api.UserRegister)
	r.POST("/user/login", api.UserLogin)
	r.GET("/post/list", api.GetPostList)
	r.GET("/post", api.GetPostDetail)
	r.GET("/post/recommend", api.GetRecommendTopic)
	r.GET("/comment/get_comments", api.GetCommentsByTopicID)
	r.GET("/search", api.SelectLikeKeyword)

	r.Run(utils.HttpPort)
}
